package com.ilab.view.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ilab.R;
import com.ilab.entity.GraphData2D;

public class DataTableListViewAdapter  extends BaseAdapter {
	private ArrayList<GraphData2D> data;
	private LayoutInflater mInflater;

	public DataTableListViewAdapter(Context context, ArrayList<GraphData2D> data) {
		this.mInflater = LayoutInflater.from(context);
		this.data = data;
	}
	
    @Override  
    public int getCount() {  
        return data.size();  
    }  

    @Override  
    public Object getItem(int position) {  
    	return data.get(position);  
    }  

    @Override  
    public long getItemId(int position) {  
        return position;  
    }

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DataTableListViewHolder holder = null;
		if (convertView != null) {
			 holder = (DataTableListViewHolder) convertView.getTag();  
		} else {
			convertView =  mInflater.inflate(R.layout.linemanager_listviewstyle, null);
			
			holder = new DataTableListViewHolder();  
	        holder.indexNum = (TextView) convertView.findViewById(R.id.lineName);  
	        holder.xValue = (TextView) convertView.findViewById(R.id.lineXAxis);  
	        holder.yValue = (TextView) convertView.findViewById(R.id.lineYAxis);
	        convertView.setTag(holder);  
		}

		holder.indexNum.setText(position);  
	    holder.xValue.setText(Float.toString(data.get(position).getXv()));  
	    holder.yValue.setText(Float.toString(data.get(position).getYv()));  
		return convertView;
	}
	
	
	private class DataTableListViewHolder{
		public TextView indexNum = null;
		public TextView xValue = null;  
		public TextView yValue = null;  
	}
}
